package com.airline.service;

import com.airline.dao.UserDAO;
import com.airline.entity.User;

public class UserService {
    private UserDAO userDAO = new UserDAO();

    /**
     * 登录业务：调用DAO层查询用户，验证账号密码
     */
    public User login(String username, String password) {
        // 简单参数校验（非空）
        if (username == null || username.trim().isEmpty() || password == null || password.trim().isEmpty()) {
            return null;
        }
        return userDAO.login(username.trim(), password.trim());
    }

    /**
     * 注册业务：调用DAO层新增用户，校验参数合法性
     */
    public boolean register(String username, String password, String realName) {
        // 参数校验（非空、用户名长度限制）
        if (username == null || username.trim().isEmpty() || username.length() < 4) {
            System.out.println("用户名不能为空且长度至少4位！");
            return false;
        }
        if (password == null || password.trim().isEmpty() || password.length() < 6) {
            System.out.println("密码不能为空且长度至少6位！");
            return false;
        }
        if (realName == null || realName.trim().isEmpty()) {
            System.out.println("真实姓名不能为空！");
            return false;
        }
        return userDAO.register(username.trim(), password.trim(), realName.trim());
    }
}